<?php echo $this->render('inc/header.htm') ?>
	<!-- Page content -->
	<div id="page">
		<!-- Wrapper -->
		<div class="wrapper">
			<!-- left column/section -->
			<?php echo $this->render('inc/_left_nav.htm') ?>
			<!-- End of left column/section -->
			
			<!-- right column/section -->
			<section class="column width6 right_content">
				<div class="add-group">
					<span class="label label-gray"><a href="user/user-list">用户列表</a></span>
					<span class="label label-gray">编辑用户信息</span>
					<hr />
					<div class="box box-info">请设置用户信息</div>
					<form action="" method="post" id="sampleform" target="tag_iframe">
						<fieldset>
							<legend>编辑用户信息</legend>
							<p>
								<label for="username" class="required">用户名:</label><br>
								<input type="text" name="username" value="<?php echo $this->user_info['user_name'] ?>" class="half" id="username"<?php if(!empty($this->user_info['user_name'])) echo ' readonly="readonly" style="border:none;background:#dedede;" ' ?>>
							</p>
							
							<p>
								<label for="password" class="required">密码:</label><br>
								<input type="password" name="password" value="" class="half" id="password">
							</p>
							<?php if(empty($this->user_info)) { ?>
							<p>
								<label for="password_confirm" class="required">确认密码:</label><br>
								<input type="password" name="password_confirm" value="" class="half" id="password_confirm">
							</p>
							<?php } ?>
							<p>
								<label for="email" class="required">Email:</label><br>
								<input type="text" name="email" value="<?php echo $this->user_info['email'] ?>" class="half" id="email">
							</p>
							
							<p>
								<label for="select1">用户组:</label><br>
								<select name="group_id" class="half" id="select1">
									<option value="0">请选择</option>
									<?php foreach($this->group_info as $v) { ?>
									<option value="<?php echo $v['group_id'] ?>"<?php if($this->user_info['group_id'] == $v['group_id']) echo ' selected="selected" ' ?>><?php echo $v['group_name'] ?></option>
									<?php } ?>
								</select>
							</p>
						</fieldset>
						<p class="box"><input type="submit" value="确定" class="btn btn-green big"> or <input type="reset" value="重置" class="btn"></p>
					</form>
				</div>
			</section>
			<!-- End of right column/section -->
		</div>
		<!-- End of Wrapper -->
	</div>
	<script type="text/javascript">
		var validator = $("#sampleform").validate({
			rules: {
				username: "required",<?php if(empty($this->user_info)) { ?>
				password: "required",
				password_confirm:'required',<?php } ?>
				email:'required'
			},
			messages: {
				username: "请输入用户名",<?php if(empty($this->user_info)) { ?>
				password: "请输入密码",
				password_confirm:'请输入确认密码',<?php } ?>
				email:'请输入email'
			},
			// the errorPlacement has to take the layout into account
			errorPlacement: function(error, element) {
				error.insertAfter(element.parent().find('label:first'));
			},
			// set new class to error-labels to indicate valid fields
			success: function(label) {
				// set &nbsp; as text for IE
				label.html("&nbsp;").addClass("ok");
			}
		});
		<?php if(empty($this->user_info)) { ?>
		$('#sampleform').submit(function(){
			if($('label.ok').size() == 4) {
				var return_value;
				$.ajax({
					type:'POST',
					url:'/admin/user/add-admin',
					data:{
						'username':$('#username').val(),
						'email':$('#email').val()
					},
					dataType:'json',
					async:false,
					success:function(json){
						if(json.success == 0) {
							alert(json.msg);
							return_value = false;
						}else {
							return_value = true;
						}
					}
				});
				return return_value;
			}
			return false;
		});
		<?php } ?>
	</script>
	<iframe src="" style="display: none;" name="tag_iframe" id="tag_iframe" frameborder="0"></iframe>
	<!-- End of Page content -->
<?php echo $this->render('inc/footer.htm') ?>